﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Server.Factory;
using ZhimeiSoft.CharmManager.Server.BLL.Interface;
using ZhimeiSoft.CharmManager.Interface;

namespace ZhimeiSoft.CharmManager.Server.Proxy.Impl
{
    public class WSBusinessServerProxyImpl : IBusinessService
    {
        private IEmployeeBLL employeeBLL;
        private IEmployeeVacationBLL employeeVacationBLL;
        private ISalonInfoBLL salonInfoBLL;
        private ICustomerBLL customerBLL;
        private IScheduleBLL scheduleBLL;
        private IServiceItemBLL serviceItemBLL;
        private IServiceItemCategoryBLL serviceItemCategoryBLL;
        private IReservationBLL reservationBLL;
        private IServiceItemDetailBLL serviceItemDetailBLL;
        private ICustomerServiceItemBLL customerServiceItemBLL;
        private ICustomerServiceItemReservationTimeBLL customerServiceItemReservationTimeBLL;
        private IToDoListBLL todoListBLL;
        private ICustomerReturnVisitBLL returnVisitBLL;
        private IPayTypeBLL payTypeBLL;
        private ICustomerPaymentBLL customerPaymentBLL;

        public WSBusinessServerProxyImpl()
        {
            employeeBLL = BaseBLLFactory.CreateEmployeeBLL();
            employeeVacationBLL = BaseBLLFactory.CreateEmployeeVacationBLL();
            salonInfoBLL = BaseBLLFactory.CreateSalonInfoBLL();
            customerBLL = BaseBLLFactory.CreateCustomerBLL();
            scheduleBLL = BaseBLLFactory.CreateScheuleBLL();
            serviceItemBLL = BaseBLLFactory.CreateServiceItemBLL();
            serviceItemCategoryBLL = BaseBLLFactory.CreateServiceItemCategoryBLL();
            reservationBLL = BaseBLLFactory.CreateReservationBLL();
            serviceItemDetailBLL = BaseBLLFactory.CreateServiceItemDetailBLL();
            customerServiceItemBLL = BaseBLLFactory.CreateCustomerServiceItemBLL();
            customerServiceItemReservationTimeBLL = BaseBLLFactory.CreateCustomerServiceItemReservationTimeBLL();
            todoListBLL = BaseBLLFactory.CreateToDoListBLL();
            returnVisitBLL = BaseBLLFactory.CreateCustomerReturnVisitBLL();
            
        }

        private IPayTypeBLL GetPayTypeBLL()
        {
            if (payTypeBLL == null)
                payTypeBLL = BaseBLLFactory.CreatePayTypeBLL();
            return payTypeBLL;
        }

        private ICustomerPaymentBLL GetCustomerPaymentBLL()
        {
            if (customerPaymentBLL == null)
                customerPaymentBLL = BaseBLLFactory.CreateCustomerPaymentBLL();
            return customerPaymentBLL;
        }

        #region 员工管理

        /// <summary>
        /// 新增员工信息
        /// </summary>
        /// <param name="employee">员工信息实体类</param>
        /// <returns>员工ID</returns>
        public bool InsertEmployee(DBEntityEmployee employee, out string error)
        {
            error = string.Empty;
            try
            {
                employeeBLL.InsertEmployee(employee);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 更新员工信息
        /// </summary>
        /// <param name="employee">员工信息实体类</param>
        public bool UpdateEmployee(DBEntityEmployee employee, out string error)
        {
            error = string.Empty;
            try
            {
                employeeBLL.UpdateEmployee(employee);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 删除员工信息
        /// </summary>
        /// <param name="employeeid">员工ID</param>
        public bool DeleteEmployee(int employeeid, out string error)
        {
            error = string.Empty;
            try
            {
                employeeBLL.DeleteEmployee(employeeid);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据员工状态查询员工信息
        /// </summary>
        /// <param name="state">状态F0E 在职、 F0Q 离职、 F0S停岗</param>
        /// <param name="dsEmployeeData">返回员工数据</param>
        /// <param name="error">错误信息</param>
        /// <returns>返回是否成功</returns>
        public bool QueryEmployeeState(string state, out System.Data.DataSet dsEmployeeData, out string error)
        {
            error = string.Empty;
            dsEmployeeData = null;
            try
            {
                dsEmployeeData = employeeBLL.QueryEmployeeState(state);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据条件过滤员工信息
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public bool QeuryEmployeeFilter(string filter, out DataSet dsEmployee, out string error)
        {
            error = string.Empty;
            dsEmployee = null;
            try
            {
                dsEmployee = employeeBLL.QeuryEmployeeFilter(filter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        #endregion

        #region 员工休假管理


        public bool InsertEmployeeVacation(DBEntityEmoloyeeVacation employeeVacation, out string error)
        {
            error = string.Empty;
            try
            {
                employeeVacationBLL.InsertEmployeeVacation(employeeVacation);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DelEmployeeVacation(DBEntityEmoloyeeVacation employeeVacation, out string error)
        {
            error = string.Empty;
            try
            {
                employeeVacationBLL.DelEmployeeVacation(employeeVacation);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateEmployeeVacation(DBEntityEmoloyeeVacation employeeVacation_old, DBEntityEmoloyeeVacation employeeVacation_new, out string error)
        {
            error = string.Empty;
            try
            {
                employeeVacationBLL.UpdateEmployeeVacation(employeeVacation_old, employeeVacation_new);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryEmployeeVacationDateTime(string startDate, string endDate, out System.Data.DataSet dsEmployeeVacation, out string error)
        {
            error = string.Empty;
            dsEmployeeVacation = null;
            try
            {
               dsEmployeeVacation = employeeVacationBLL.QueryEmployeeVacationDateTime(startDate, endDate);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryEmployeeVacationEmployeeID(int employeeID, string startDate, string endDate, out System.Data.DataSet dsEmployeeVacation, out string error)
        {
            error = string.Empty;
            dsEmployeeVacation = null;
            try
            {
                dsEmployeeVacation = employeeVacationBLL.QueryEmployeeVacationEmployeeID(employeeID, startDate, endDate);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据当天返回休假中的员工
        /// </summary>
        /// <param name="vacationDate">当前日期</param>
        /// <param name="state">休假状态</param>
        /// <param name="dsEmployeeVacation">返回数据集</param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public bool QueryEmployeeVacationDay(string vacationDate, string state, out DataSet dsEmployeeVacation, out string error)
        {
            error = string.Empty;
            dsEmployeeVacation = null;
            try
            {
                dsEmployeeVacation = employeeVacationBLL.QueryEmployeeVacationDay(vacationDate, state);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        #endregion

        #region 店铺信息管理

        public bool QuerySalonInfo(out System.Data.DataSet dsSalonInfo, out string error)
        {
            error = string.Empty;
            dsSalonInfo = null;
            try
            {
                dsSalonInfo = salonInfoBLL.getSalonInfo();
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        #endregion

        #region 客户信息管理

        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public bool InsertCustomer(DBEntityCustomInfo customerInfo, out string error)
        {
            error = string.Empty;
            try
            {
                customerBLL.InsertCustomer(customerInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 修改客户信息
        /// </summary>
        /// <param name="customer"></param>
        public bool UpdateCustomer(DBEntityCustomInfo customerInfo, out string error)
        {
            error = string.Empty;
            try
            {
                customerBLL.UpdateCustomer(customerInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 删除客户信息
        /// </summary>
        /// <param name="customerID"></param>
        public bool DeleteCustomer(int customerID, out string error)
        {
            error = string.Empty;
            try
            {
                customerBLL.DeleteCustomer(customerID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据用户状态查询用户信息
        /// </summary>
        /// <param name="stateStr">用户状态</param>
        /// <param name="dsCustomInfo">返回数据</param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public bool QueryCustomState(string stateStr, out System.Data.DataSet dsCustomInfo, out string error)
        {
            dsCustomInfo = null;
            error = string.Empty;
            try
            {
                dsCustomInfo = customerBLL.QueryCustomState(stateStr);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据用户ID获取用户信息
        /// </summary>
        /// <param name="customerID">用户ID</param>
        /// <param name="dsCustomInfo">返回用户数据</param>
        /// <param name="error">错误信息</param>
        /// <returns>是否成功</returns>
        public bool QueryCustomerID(int customerID, out DataSet dsCustomInfo, out string error)
        {
            dsCustomInfo = null;
            error = string.Empty;
            try
            {
                dsCustomInfo = customerBLL.QueryCustomID(customerID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据会员姓名查询信息
        /// </summary>
        /// <param name="customName"></param>
        /// <returns></returns>
        public bool QueryCustomName(string customName, out DataSet dsCustomInfo, out string error)
        {
            error = string.Empty;
            dsCustomInfo = null;
            try
            {
                dsCustomInfo = customerBLL.QueryCustomName(customName);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        #endregion

        #region 预约管理已经不用


        public bool InsertScheduleCustom(DBEntitySchedule scheduleInfo, DBEntityScheduleCustom scheduleCustom, out string error)
        {
            error = string.Empty;
            try
            {
                scheduleBLL.InsertScheduleCustom(scheduleInfo, scheduleCustom);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteScheduleCustom(DBEntitySchedule scheduleInfo, DBEntityScheduleCustom scheduleCustom, out string error)
        {
            error = string.Empty;
            try
            {
                scheduleBLL.DeleteScheduleCustom(scheduleInfo, scheduleCustom);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateScheduleCustom(DBEntitySchedule scheduleInfo, DBEntityScheduleCustom scheduleCustomOld,
            DBEntityScheduleCustom scheduleCustomNew, out string error)
        {
            error = string.Empty;
            try
            {
                scheduleBLL.UpdateScheduleCustom(scheduleInfo, scheduleCustomOld, scheduleCustomNew);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryScheduleState(string scheduleState, out System.Data.DataSet dsSchedule, out string error)
        {
            error = string.Empty;
            dsSchedule = null;
            try
            {
                dsSchedule = scheduleBLL.QueryScheduleState(scheduleState);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据用户ID获取提醒信息
        /// </summary>
        /// <param name="customerID">用户ID</param>
        /// <param name="scheduleState">提醒状态</param>
        /// <returns></returns>
        public bool QueryScheduleCustomID(int customerID, string scheduleState, out DataSet dsSchedule, out string error)
        {
            error = string.Empty;
            dsSchedule = null;
            try
            {
                dsSchedule = scheduleBLL.QueryScheduleCustomID(customerID, scheduleState);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据用户ID以及当前时间查询提醒信息.
        /// </summary>
        /// <param name="customerID">用户ID</param>
        /// <param name="currTime">当前时间</param>
        /// <param name="dsSchedule">提醒数据集</param>
        /// <param name="error">错误信息</param>
        /// <returns>返回是否成功</returns>
        public bool QueryScheduleCustomDateTime(int customerID, DateTime currTime, out DataSet dsSchedule, out string error)
        {
            error = string.Empty;
            dsSchedule = null;
            try
            {
                dsSchedule = scheduleBLL.QueryScheduleCustomDateTime(customerID, currTime);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据月份查询预约记录
        /// </summary>
        /// <param name="queryYear">查询年</param>
        /// <param name="queryMonth">查询月</param>
        /// <returns></returns>
        public bool QueryScheduleMonth(int queryYear, int queryMonth, out DataSet dsSchedule, out string error)
        {
            error = string.Empty;
            dsSchedule = null;
            try
            {
                dsSchedule = scheduleBLL.QueryScheduleMonth(queryYear, queryMonth);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据日查询预约记录
        /// </summary>
        /// <param name="queryYear">年</param>
        /// <param name="queryMonth">月</param>
        /// <param name="queryDay">日</param>
        /// <returns></returns>
        public bool QueryScheduleDay(int queryYear, int queryMonth, int queryDay, out DataSet dsSchedule, out string error)
        {
            error = string.Empty;
            dsSchedule = null;
            try
            {
                dsSchedule = scheduleBLL.QueryScheduleDay(queryYear, queryMonth, queryDay);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        #endregion

        #region 新预约管理
        /// <summary>
        /// 增加预约信息
        /// </summary>
        public bool AddResveration(DBEntityReservation reservatoinInfo, DataSet dsReservationServiceItem, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.AddResveration(reservatoinInfo, dsReservationServiceItem);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
            
        }
        /// <summary>
        /// 修改预约信息
        /// </summary>
        /// <param name="reservatioinInfo"></param>
        /// <param name="dsReservationServiceItem"></param>
        public bool UpdateReservation(DBEntityReservation reservatioinInfo, DataSet dsReservationServiceItem, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.UpdateReservation(reservatioinInfo, dsReservationServiceItem);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据年月查询预约信息
        /// </summary>
        /// <param name="queryYear">年</param>
        /// <param name="queryMonth">月</param>
        /// <param name="dsReservation">预约信息</param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public bool QueryReservationMonth(int queryYear, int queryMonth, string state, out DataSet dsReservation, out string error)
        {
            error = string.Empty;
            dsReservation = null;
            try
            {
                dsReservation = reservationBLL.QueryReservationMonth(queryYear, queryMonth, state);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据信息查询预约ＩＤ
        /// </summary>
        /// <param name="reservatioinInfo"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool QueryResverationID(DBEntityReservation reservatioinInfo, out string error)
        {
            error = string.Empty;
            try
            {
                reservatioinInfo.RESERVATIONID = reservationBLL.QueryResverationID(reservatioinInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 获取预约信息
        /// </summary>
        /// <param name="queryYear">查询年</param>
        /// <param name="queryMonth">查询月</param>
        /// <param name="queryDay">查询日</param>
        /// <param name="stateStr">预约状态</param>
        /// <returns></returns>
        public bool QueryResveration(int queryYear, int queryMonth, int queryDay, string stateStr, out DataSet dsReservation, out string error)
        {
            dsReservation = null;
            error = string.Empty;
            try
            {
                dsReservation = reservationBLL.GetResveration(queryYear, queryMonth, queryDay, stateStr);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        
        /// <summary>
        /// 获取员工预约信息
        /// </summary>
        /// <param name="queryYear">查询年</param>
        /// <param name="queryMonth">查询月</param>
        /// <param name="queryDay">查询日</param>
        /// <param name="employeeID">员工ID</param>
        /// <param name="stateStr">预约状态</param>
        /// <returns></returns>
        public bool QueryReservationEmployee(int queryYear, int queryMonth, int queryDay, int employeeID, string stateStr, out DataSet dsReservationEmployee, out string error)
        {
            dsReservationEmployee = null;
            error = string.Empty;
            try
            {
                dsReservationEmployee = reservationBLL.GetReservationEmployee(queryYear, queryMonth, queryDay, employeeID, stateStr);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据时间和会员查询预约
        /// </summary>
        /// <param name="querYear">年</param>
        /// <param name="queryMonth">月</param>
        /// <param name="queryDay">日</param>
        /// <param name="customID">会员ID</param>
        /// <param name="dsReservation">返回查询结果</param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public bool QueryReservationCustom(int queryYear, int queryMonth, int queryDay, int customID, out DataSet dsReservation, out string error)
        {
            dsReservation = null;
            error = string.Empty;
            try
            {
                dsReservation = reservationBLL.QueryReservationCustom(queryYear, queryMonth, queryDay, customID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryCustomerServiceItemReservationTime(string sFilter, out DataSet dsDetail, out string error)
        {
            dsDetail = new DataSet();
            error = string.Empty;
            try
            {
                dsDetail = customerServiceItemReservationTimeBLL.QueryCustomerServiceItemDetail(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据主表的状态获取明细数据
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public bool QueryReservationServiceItemForReservationState(string state, out DataSet dsReservationServiceItem, out string error)
        {
            dsReservationServiceItem = null;
            error = string.Empty;
            try
            {
                dsReservationServiceItem = reservationBLL.QueryReservationServiceItemForReservationState(state);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据预约ID查询对应的服务项目
        /// </summary>
        /// <param name="reservationID"></param>
        /// <returns></returns>
        public bool QueryReservationServiceItem(int reservationID, out DataSet dsReservationServiceItem, out string error)
        {
            dsReservationServiceItem = null;
            error = string.Empty;
            try
            {
                dsReservationServiceItem = reservationBLL.QueryReservationServiceItem(reservationID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 计算下一次的预约时间
        /// </summary>
        /// <param name="customerServiceItemID">预约的项目ID</param>
        /// <param name="iday">返回下一次的预约天数</param>
        public bool ComputerNextReservation(int customerServiceItemID, out int iday, out string error)
        {
            error = string.Empty;
            iday = 0;
            try
            {
                iday = reservationBLL.ComputerNextReservation(customerServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 查询会员卡项预约情况
        /// </summary>
        /// <param name="customID">会员ID</param>
        /// <param name="customServiceItemID">会员服务项目ID</param>
        /// <returns></returns>
        public bool QeuryReservationCustomServiceItem(int customID, int customServiceItemID, out DataSet dsReservation, out string error)
        {
            error = string.Empty;
            dsReservation = new DataSet();
            try
            {
                dsReservation = reservationBLL.QeuryReservationCustomServiceItem(customID, customServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 查询会员卡预约情况
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public bool QueryReservationCustomServiceItemFilter(string filter, out DataSet dsCustomServiceItem, out string error)
        {
            error = string.Empty;
            dsCustomServiceItem = new DataSet();
            try
            {
                dsCustomServiceItem = reservationBLL.QueryReservationCustomServiceItemFilter(filter);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据预约ID查询详细项目
        /// </summary>
        /// <param name="reservationID">预约ＩＤ</param>
        /// <returns></returns>
        public bool QueryReservationServiceItemDetail(int reservationID, out DataSet dsReservationServiceItem, out string error)
        {
            error = string.Empty;
            dsReservationServiceItem = new DataSet();
            try
            {
                dsReservationServiceItem = reservationBLL.QueryReservationServiceItemDetail(reservationID);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 预约项目调整
        /// </summary>
        /// <param name="ajdustReservationID">当前调整的预约项目ID</param>
        /// <param name="adjustDateTime">预约调整后的时间</param>
        /// <param name="customServiceItemID">要调整的时间</param>
        /// <param name="customID">会员</param>
        public bool AdjustReservationCustomServiceItem(int reservationID, DateTime adjustDateTime, int customServiceItemID, int customID, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.AdjustReservationCustomServiceItem(reservationID, adjustDateTime, customServiceItemID, customID);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 预约调整
        /// </summary>
        /// <param name="entityReservation"></param>
        public bool AdjustReservation(DBEntityReservation entityReservation, int reservationEmployeeID, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.AdjustReservation(entityReservation, reservationEmployeeID);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 更新预约状态
        /// </summary>
        /// <param name="reservationID"></param>
        /// <param name="customServiceItemID"></param>
        /// <param name="state"></param>
        public bool UpdateReservationCustomServiceItemState(int reservationID, int customServiceItemID, int employeeID, string state, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.UpdateReservationCustomServiceItemState(reservationID, customServiceItemID, employeeID, state);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 更新过期的预约状态
        /// </summary>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public bool CheckAllReservationState(out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.CheckAllReservationState();
            }catch(Exception ex){
                error = ex.Message;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 刷新预约项目的提示
        /// </summary>
        /// <param name="reservationInfo"></param>
        public bool refershReservationToDoList(DBEntityReservation reservationInfo, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.refershReservationToDoList(reservationInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 查询会员预约情况
        /// </summary>
        /// <param name="customID">会员ID</param>
        /// <param name="queryYear">查询年</param>
        /// <param name="queryMonth">查询月</param>
        /// <returns></returns>
        public bool QueryCustomReservation(int customID, int queryYear, int queryMonth, out DataSet dsReservationCustomInfo, out string error)
        {
            error = string.Empty;
            dsReservationCustomInfo = null;
            try
            {
                dsReservationCustomInfo = reservationBLL.QueryCustomReservation(customID, queryYear, queryMonth);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 调整预约时间
        /// </summary>
        /// <param name="reservationID"></param>
        public bool AdjstReservationCurrTime(DBEntityReservation reservationInfo, out string error)
        {
            error = string.Empty;
            try
            {
                reservationBLL.AdjstReservationCurrTime(reservationInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }
            return true;
        }
        #endregion

        #region 服务项目管理

        #region 服务项目分类
        public bool InsertServiceItemCategory(DBEntityServiceItemCategory category, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemCategoryBLL.InsertServiceItemCategory(category);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateServiceItemCategory(DBEntityServiceItemCategory category, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemCategoryBLL.UpdateServiceItemCategory(category);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteServiceItemCategory(int categoryid, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemCategoryBLL.DeleteServiceItemCategory(categoryid);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryServiceItemCategory(string sFilter, out DataSet dsCategory, out string error)
        {
            error = string.Empty;
            dsCategory = null;
            try
            {
                dsCategory = serviceItemCategoryBLL.QueryServiceItemCategory(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        #endregion

        #region 服务项目
        public bool InsertServiceItem(DBEntityServiceItem serviceItem, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemBLL.InsertServiceItem(serviceItem);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateServiceItem(DBEntityServiceItem serviceItem, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemBLL.UpdateServiceItem(serviceItem);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool SetServiceItemState(int serviceItemID, string sState, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemBLL.SetServiceItemState(serviceItemID, sState);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryServiceItem(string sFilter, out DataSet dsServiceItem, out string error)
        {
            error = string.Empty;
            dsServiceItem = new DataSet();
            try
            {
                dsServiceItem = serviceItemBLL.QueryServiceItem(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        #endregion

        #region 服务项目明细
        public bool QueryServiceItemDetail(int iServiceItemID, out DataSet ds, out string error)
        {
            error = string.Empty;
            ds = new DataSet();
            try
            {
                ds = serviceItemDetailBLL.QueryServiceItemDetail(iServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool SubmitServiceItmeDetail(DataSet ds, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemDetailBLL.SubmitServiceItmeDetail(ds);
                return true;
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
        }

        public bool DeleteServiceItemDetail(int iServiceItemID, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemDetailBLL.DeleteServiceItemDetail(iServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool InsertServiceItemDetail(DBEntityServiceItemDetail entity, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemDetailBLL.InsertServiceItemDetail(entity);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateServiceItemDetail(DBEntityServiceItemDetail entity, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemDetailBLL.UpdateServiceItemDetail(entity);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteServiceItemDetailById(int detailID, out string error)
        {
            error = string.Empty;
            try
            {
                serviceItemDetailBLL.DeleteServiceItemDetailByID(detailID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        #endregion
        #endregion

        #region 代办事项
        /// <summary>
        /// 插入一个代办事项
        /// </summary>
        /// <param name="todoListInfo">信息类</param>
        public bool InsertToDoList(DBEntityToDoList todoListInfo, out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.InsertToDoList(todoListInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 插入一个待办事项，并且和预约关联
        /// </summary>
        /// <param name="todoListInfo"></param>
        /// <param name="reservationToDoListInfo"></param>
        public bool InsertResverationToDoList(DBEntityToDoList todoListInfo, DBEntityReservationToDoList reservationToDoListInfo, out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.InsertResverationToDoList(todoListInfo, reservationToDoListInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 修改一个代办事项
        /// </summary>
        /// <param name="todoListInfo">代办事项</param>
        public bool UpdateToDoList(DBEntityToDoList todoListInfo, out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.UpdateToDoList(todoListInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 删除一个代办事项
        /// </summary>
        /// <param name="todoListID">待办事项ＩＤ</param>
        public bool DeleteToDoList(int todoListID, out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.DeleteToDoList(todoListID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 删除预约与待办事项对应表
        /// </summary>
        /// <param name="reservationToDoListInfo"></param>
        public bool DeleteResverationToDoList(DBEntityReservationToDoList reservationToDoListInfo, out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.DeleteResverationToDoList(reservationToDoListInfo);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据时间状态获取代办事项
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public bool GetStateToDoList(DateTime startDate, string state, out DataSet dsToDoList, out string error)
        {
            error = string.Empty;
            dsToDoList = null;
            try
            {
                dsToDoList = todoListBLL.GetStateToDoList(startDate, state);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryTodoList(string sFilter, out DataSet dsTodoList, out string error)
        {
            error = string.Empty;
            dsTodoList = new DataSet();
            try
            {
                dsTodoList = todoListBLL.QueryTodoList(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool CheckAllExpiredTodoState(out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.CheckAllExpiredTodoState();
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据todolistID查询预约
        /// </summary>
        /// <param name="todoListID"></param>
        /// <returns></returns>
        public bool QueryReservationForToDoListID(int todoListID, out DataSet dsReservation, out string error)
        {
            error = string.Empty;
            dsReservation = null;
            try
            {
                dsReservation = todoListBLL.QueryReservationForToDoListID(todoListID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        #endregion

        #region 会员服务项目管理


        public bool InsertCustomerServiceItem(DBEntityCustomerServiceItem csi, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemBLL.InsertCustomerServiceItem(csi);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateCustomerServiceItem(DBEntityCustomerServiceItem csi, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemBLL.UpdateCustomerServiceItem(csi);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteCustomerServiceItem(int iCustomerServiceItemID, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemBLL.DeleteCustomerServiceItem(iCustomerServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryCustomerServiceItem(string sFilter, out DataSet ds, out string error)
        {
            error = string.Empty;
            ds = new DataSet();
            try
            {
                ds = customerServiceItemBLL.QueryCustomerServiceItem(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }


        public bool InsertCustomerServiceItemReservationTime(DBEntityCustomerServiceItemReservationTime detail, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemReservationTimeBLL.InsertCustomerServiceItemDetail(detail);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateCustomerServiceItemReservationTime(DBEntityCustomerServiceItemReservationTime detail, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemReservationTimeBLL.UpdateCustomerServiceItemDetail(detail);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteCustomerServiceItemReservationTime(string sFilter, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemReservationTimeBLL.DeleteCustomerServiceItemDetail(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool SubmitCustomerServiceItmeReservationTime(DataSet ds, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemReservationTimeBLL.SubmitCustomerServiceItmeReservationTime(ds);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool MarkTodoListCompleted(int todoListID, out string error)
        {
            error = string.Empty;
            try
            {
                todoListBLL.MarkCompleted(todoListID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 会员服务扣减
        /// </summary>
        /// <param name="customServiceItemID">服务项目ID</param>
        /// <param name="minusRemain">扣减次数</param>
        /// <param name="lastServiceTime">服务时间</param>
        /// <param name="cMemo">说明</param>
        /// <param name="employeeID">员工ID</param>
        /// <returns></returns>
        public bool CompleteCustomServiceItem(int customServiceItemID, int minusRemain, string lastServiceTime,
            string cMemo, string employeeID, DBEntityCustomerServiceItem customerServiceItem, int reservationID, out string error)
        {
            error = string.Empty;
            try
            {
                customerServiceItemBLL.CompleteCustomServiceItem(customServiceItemID, minusRemain, lastServiceTime, cMemo, employeeID, customerServiceItem, reservationID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 根据用户疗程项目查询消费记录
        /// </summary>
        /// <param name="customServiceItemID"></param>
        /// <returns></returns>
        public bool QueryCustomServiceItemConsume(int customServiceItemID, out DataSet dsServiceItemConsume, out string error)
        {
            error = string.Empty;
            dsServiceItemConsume = null;
            try
            {
                dsServiceItemConsume = customerServiceItemBLL.QueryCustomServiceItemConsume(customServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据用户预约记录查询扣减次数
        /// </summary>
        /// <param name="customServiceItemID"></param>
        /// <returns></returns>
        public bool QeuryCustomServiceItemConsumeReservationID(int reservationID, out DataSet dsServiceItemConsume, out string error)
        {
            error = string.Empty;
            dsServiceItemConsume = null;
            try
            {
                dsServiceItemConsume = customerServiceItemBLL.QeuryCustomServiceItemConsumeReservationID(reservationID);
            }
            catch(Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        /// <summary>
        /// 检车是否能够删除会员服务项目
        /// </summary>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool CheckDeleteCustomServiceItem(int customServiceItemID, out string error)
        {
            error = string.Empty;
            try
            {
                return customerServiceItemBLL.CheckDeleteCustomServiceItem(customServiceItemID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }

        }
        #endregion

        #region 会员回访


        public bool InsertCustomerReturnVisit(DBEntityCustomerReturnVisit visit, out string error)
        {
            error = string.Empty;
            try
            {
                returnVisitBLL.InsertCustomerReturnVisit(visit);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateCustomerReturnVisit(DBEntityCustomerReturnVisit visit, out string error)
        {
            error = string.Empty;
            try
            {
                returnVisitBLL.UpdateCustomerReturnVisit(visit);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteCustomerReturnVisit(int visitID, out string error)
        {
            error = string.Empty;
            try
            {
                returnVisitBLL.DeleteCustomerReturnVisit(visitID);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool QueryCustomerReturnVisit(string sFilter, out DataSet ds, out string error)
        {
            error = string.Empty;
            ds = new DataSet();
            try
            {
                ds = returnVisitBLL.QueryCustomerReturnVisit(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
            
        }

        #endregion

        #region 支付方式


        public bool QueryPayType(string sFilter, out DataSet ds, out string error)
        {
            error = string.Empty;
            ds = new DataSet();
            try
            {
                ds = GetPayTypeBLL().GetPayType(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool InsertPayType(DBEntityPayType entity, out string error)
        {
            error = string.Empty;
            try
            {
                this.GetPayTypeBLL().InsertPayType(entity);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
            }
            return true;
        }

        public bool UpdatePayType(DBEntityPayType entity, out string error)
        {
            error = string.Empty;
            try
            {
                this.GetPayTypeBLL().UpdatePayType(entity);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeletePayType(int paytype_id, out string error)
        {
            error = string.Empty;
            try
            {
                this.GetPayTypeBLL().DeletePayType(paytype_id);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }
        #endregion

        #region 会员充值信息

        public bool QueryCustomerPayment(string sFilter, out DataSet ds, out string error)
        {
            error = string.Empty;
            ds = new DataSet();
            try
            {
                ds = this.GetCustomerPaymentBLL().GetCustomerPayment(sFilter);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool InsertCustomerPayment(DBEntityCustomerPayment entity, out string error)
        {
            error = string.Empty;
            try
            {
                this.GetCustomerPaymentBLL().InsertCustomerPayment(entity);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool UpdateCustomerPayment(DBEntityCustomerPayment entity, out string error)
        {
            error = string.Empty;
            try
            {
                this.GetCustomerPaymentBLL().UpdateCustomerPayment(entity);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        public bool DeleteCustomerPayment(int payment_id, out string error)
        {
            error = string.Empty;
            try
            {
                this.GetCustomerPaymentBLL().DeleteCustomerPayment(payment_id);
            }
            catch (Exception ex)
            {
                error = ex.Message + "\r\n" + ex.StackTrace;
                return false;
            }
            return true;
        }

        #endregion

    }
}
